package com.huazi.statistics.schedule;

import com.huazi.statistics.service.DailyService;
import com.huazi.statistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author shkstart
 * @create 2021-04-02 9:28
 */
@Component
public class ScheduleTask {//定时器类
    @Autowired
    DailyService dailyService;

    //0/5 * * * * ?表示每隔5秒执行一次这个方法
//    @Scheduled(cron="0/5 * * * * ?")
//    public void test1(){
//        System.out.println("************test1执行了..");
//    }
    //每天凌晨1点
    @Scheduled(cron="0 0 1 * * ? ")
    public void test2(){
        System.out.println("************test2执行了..");
        //获取前一天日期
        Date date = DateUtil.addDays(new Date(), -1);
        String forDate = DateUtil.formatDate(date);
        //按照凌晨1点进行前一天的数据统计
        dailyService.registerCount(forDate);
    }
}
